home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / vb_g_prt / genprint.txt < prev    next >
Text File  |  1994-06-03  |  5KB  |  134 lines

  1. GENPRINT - Generalized Printer for VB
  2.  
  3. by Guinn Unger  
  4. Unger Business Systems
  5. 11926 Barrett Brae
  6. Houston, TX  77072-4004
  7. Phone: (713) 498-8517  Fax: (713) 498-8518
  8. Compuserve: Guinn Unger, 71053,2332
  9.  
  10. NOTE:
  11. The GENPRINT setup routine was failing with a PostScript printer.  It
  12. turns out that the dmout.dmDriverExtra must be set to 0 for PS printers
  13. to initialize.  This change is hard-coded in the routine now.
  14. (Note:  There is the potential that this could cause problems with
  15. printer drivers which use the private data area.  This has not been
  16. explored any further at this time.)
  17.  
  18. The GENPRINT forms and routines are designed to give the VB programmer
  19. additional flexibility over using the VB PRINTER object.  The primary
  20. advantages are:
  21.  
  22.     1.  The ability to abort the print job.  This is a significant
  23.     shortcoming of the VB PRINTER object in some situations.
  24.  
  25.     2.  The ability to select/change printers without changing the
  26.     Windows default printer.  This includes changing the printer
  27.     orientation.
  28.  
  29.     3.  The ability to have more than one printer active.
  30.  
  31. GENPRINT consists of the following:
  32.  
  33.     1.  A form (GPRINTER.FRM) which acts as a dummy form and contains
  34.     the CBK.VBX custom control.  This form is not actually necessary
  35.     if the appropriate controls are present on another form.
  36.  
  37.     2.  A form (ABORTFOR.FRM) which is displayed while printing is in
  38.     progress.  It contains a command button which is pressed to abort
  39.     the print job.
  40.  
  41.     3.  A form (PRTSETUP.FRM) which mimics the dialog box used in 
  42.     Microsoft Word.
  43.  
  44.     4.  A module (GPRINTER.BAS) which contains the various subs and
  45.     functions which are called by the user.
  46.  
  47.     5.  A custom callback control (CBK.VBX) which is necessary for
  48.     the abort function to work properly.  This custom control was
  49.     supplied as part of Appleman's book and may be distributed
  50.     freely.
  51.  
  52. General Procedure for using GENPRINT
  53.  
  54.     1.  The functions are called as follows:
  55.  
  56.             prhdc = GenPrinterSetup(ThisPrinter) 
  57.         
  58.         where prhdc is an integer which now contains the device 
  59.         context for ThisPrinter.  ThisPrinter is a string of the
  60.         form "HP LaserJet IIP,HPPCL,LPT1:" as stored in the
  61.         WIN.INI file.  Note that prhdc is passed to virtually
  62.         all of the other GENPRINT routines.  This routine as
  63.         written call DefaultFontSetup and uses "Ariel" font in 
  64.         10 pt size.
  65.  
  66.         SetupDocInfo ("PROGNAME")
  67.  
  68.         This supplies the information used by Print Manager.
  69.  
  70.         SetAbortCallback (prhdc)
  71.         
  72.         This sets up the abort procedure.
  73.  
  74.         ShowAbortForm (False)  'must not be system modal
  75.  
  76.         This displays the abort form.
  77.  
  78.         di = StartDocument(prhdc)
  79.  
  80.         This tells Print Manager that we are starting a document.
  81.  
  82.         di = StartAPage(prhdc)
  83.  
  84.         Start a page!
  85.  
  86.         PrintText prhdc, AString
  87.  
  88.     {There are numerous other functions which can now be called to draw
  89.      lines, rectangles, etc.  The font can also be changed.  See the
  90.      GPRINTER.BAS module for available functions.}
  91.  
  92.         di = EndAPage(prhdc)
  93.  
  94.         This is called each time you want to end a page.  If
  95.         more pages are to be printed, be sure to call StartAPage
  96.         again.
  97.    
  98.         di = EndDocument(prhdc)
  99.  
  100.         This tells Print Manager that the document is finished.
  101.    
  102.         UnloadAbortForm
  103.  
  104.         Get rid of the abort form.
  105.  
  106.        GenPrinterClose prhdc
  107.  
  108.         Clean up after printer.  After this call prhdc is no
  109.         longer valid.
  110.  
  111. MISCELLANEOUS ROUTINES
  112.  
  113.     The ClipString and SplitLines routines were developed to allow the
  114. user to clip or split a text string which might be too long to fit in a
  115. given space.  The maximum length passed to each routine is in inches.  
  116. ClipString simply trims the string to the maximum number of characters which
  117. will fit in the given length.  Split lines parses the string into 3 separate
  118. strings and throws away any extra.  (The number of strings could be increased
  119. easily.)  Both routines take into account the current font size and other
  120. characteristics.
  121.  
  122. OTHER INFORMATION
  123.  
  124.      Several routines are included which show information about the
  125. DevMode structure, printers, fonts, etc.  Feel free to experiment
  126. with these as you are using the routines.     
  127.  
  128.      These routines have primarily been tested with laser printers 
  129. (300 dpi).  If you use them with other printers, be sure to test them 
  130. carefully.  The routines seem to work fine with local and network printers.
  131.  
  132.      If would be relatively easy to add additional functions to the 
  133. routines.  See Appleman's book for more information.
  134.